/ Assembly List / LJCDataAccess / DataAccess / GetDataSet

Namespace - LJCDataAccess


Parameters
sql - The Select SQL statement.
tableMapping - The table map collection.

Returns

A reference to the DataSet object.

Syntax

C#
public DataSet GetDataSet(String sql, DataTableMappingCollection tableMapping = null)

Executes a Select statement and retrieves the DataSet object. (E)

Example

C#
// See the DataAccess setup code on the DataAccess class page.

// Executes a Select statement and retrieves the DataSet object.
private static void GetDataSet(DataAccess dataAccess)
{
    string sql = "select * from firstTable; select * from secondTable";

    // Create table map collection.
    TableMapping tableMapping = new TableMapping();
    tableMapping.AddTableMap("FirstTable");
    tableMapping.AddColumnMap("FirstTable", "OriginalName", "NewName");
    tableMapping.AddTableMap("SecondTable");
    tableMapping.AddColumnMap("SecondTable", "OriginalName", "NewName");

    var dataSet = dataAccess.GetDataSet(sql, tableMapping.TableMaps);
    if (dataSet != null)
    {
        var dataTable = dataSet.Tables["FirstTable"];
        if (dataTable != null)
        {
            foreach (DataRow dataRow in dataTable.Rows)
            {
                for int index = 0; index < dataTable.Columns.Count; index++)
                {
                    string value = dataRow[index].ToString();
                }
            }
        }

        dataTable = dataSet.Tables["SecondTable"];
        if (dataTable != null)
        {
            foreach (DataRow dataRow in dataTable.Rows)
            {
                for int index = 0; index < dataTable.Columns.Count; index++)
                {
                    string value = dataRow[index].ToString();
                }
            }
        }
    }
}

Copyright © Lester J. Clark and Contributors.
Licensed under the MIT License.